YUI.add('wfmenu', function (Y) {
    var menu = Y.youxuMenu = Y.one("#youxu-menu");
    
    var mtpl = '<li class="yui3-menuitem"><a class="yui3-menuitem-content" href="#" id="menu-item-{mid}">{mname}</a></li>';
    
    menu.plug(Y.Plugin.NodeMenuNav, { autoSubmenuDisplay: true, mouseOutHideDelay: 250,submenuShowDelay : 10 });

    //  Show the menu now that it is ready

    menu.get("ownerDocument").get("documentElement").removeClass("yui3-loading");
    
    menu.on('click',function(e){
    	e.preventDefault();
    	var mid = e.target.get('id');
    	if(mid)mid = mid.substring(10);
    	if(mid == 'logout'){
    		window.location.replace("/notrpclogin?logout=true&next=workflow");
    	}else if(mid == 'login'){
    		window.location.href = '/login.html#next=workflow';
    	}else if(mid == 'about'){
    		Y.showAboutPanel();
    	}else if(mid == 'help'){
    		Y.showHelpPanel();
    	}
    });
    
    Y.on('loginStatus',function(e){
    	var mg = menu.one('#login-out-ul');
    	mg.empty();
    	if(e.login){
    		 mg.append(Y.Lang.sub(mtpl,{mname:e.user.email,mid:'login-name'}));
    		 mg.append(Y.Lang.sub(mtpl,{mname:Y.translator.menuItemLogout(),mid:'logout'}));
    	}else{
    		mg.append(Y.Lang.sub(mtpl,{mname:Y.translator.menuItemLogin(),mid:'login'}));
    	}
    });
    
},'0.0.1',{requires:['node-menunav', 'node-menunav-core-css', 'custommenunavskin']});